# 定义类
from selenium.webdriver.common.by import By
from selenium.webdriver.ie.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Register:
    def __init__(self, driver):
        self.driver=driver
        self.phone=By.ID, "phone"
        self.password=By.ID, "password"
        self.verifycode=By.ID, "verifycode"
        self.get_phone_code=By.ID, "getPhoneCode"
        self.phone_code=By.ID, "phone_code"
        self.lg_btn=By.CLASS_NAME, "lg_btn"
    def input_phone(self, phone):
        """输入手机号"""
        # self.driver.find_element(*self.phone).send_keys(phone)
        element=WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.phone))
        element.clear()
        element.send_keys(phone)
    def input_password(self, password):
        """输入密码"""
        # self.driver.find_element(*self.password).send_keys(password)
        element=WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.password))
        element.clear()
        element.send_keys(password)

    def input_verifycode(self, verifycode='8888'):
        """输入验证码"""
        # self.driver.find_element(*self.verifycode).send_keys(verifycode)
        element=WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.verifycode))
        element.clear()
        element.send_keys(verifycode)
    def click_get_phone_code(self):
        """点击获取手机验证码"""
        # self.driver.find_element(*self.get_phone_code).click()
        element=WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(self.get_phone_code))
        element.click()
    def input_phone_code(self,phone_code='666666'):
        """输入短信验证码"""
        # self.driver.find_element(*self.phone).send_keys(phone_code)
        element=WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(self.phone_code))
        element.clear()
        element.send_keys(phone_code)
    def click_lg_btn(self):
        """点击注册按钮"""
        # self.driver.find_element(*self.lg_btn).click()
        element=WebDriverWait(self.driver,10).until(EC.visibility_of_element_located(self.lg_btn))
        element.click()
    def register(self,phone,password,verifycode='8888',phone_code='666666'):
        self.input_phone(phone)
        self.input_password(password)
        self.input_verifycode(verifycode)
        self.click_get_phone_code()
        self.input_phone_code(phone_code)
        self.click_lg_btn()

